package com.squareup.picasso;

import android.graphics.drawable.Drawable;

import com.squareup.picasso.Picasso.LoadedFrom;

final class TargetAction extends Action<Object> {
    private final Object obj;
    private Callback callback;

    TargetAction(Picasso picasso, Request data, int errorResId, String key, Callback callback) {
        super(picasso, null, data, errorResId, key);
        this.obj = new Object();
        this.callback = callback;
    }

    public final void cancel() {
        super.cancel();
        this.callback = null;
    }

    final void complete(Drawable result, LoadedFrom from) {
        if(this.callback != null) {
            this.callback.onSuccess(result, from);
        }
    }

    final void error(Exception e) {
        if(this.callback != null) {
            this.callback.onError(e);
        }
    }

    final Object getTarget() {
        return this.obj;
    }
}

